#ifndef DEMUXER_H
#define DEMUXER_H


#include "yuvfilespec.h"
#include "pcmfilespec.h"
#include <QDebug>
#include <QFile>
extern "C" {

    #include<libavformat/avformat.h>
}

class Demuxer
{

private:
    YUVFileSpec* _yuvFileSpec = nullptr;
    PCMFileSpec* _pcmFileSpec = nullptr;
    AVFormatContext* _fmtContext = nullptr;
    AVCodecContext* _vCodecContext = nullptr;
    AVCodecContext* _aCodecContext = nullptr;
    int _aStreamIdx;
    int _vStreamIdx;
    QFile* _vOutFile = nullptr;
    QFile* _aOutFile = nullptr;
    AVFrame* _frame = nullptr;
    AVPacket* _packet = nullptr;

    int init(enum AVMediaType type,int* streamIdx, AVCodecContext** codeContext);

    int initVideo();
    int initAudio();

    int decode(AVCodecContext *codecContext, AVPacket *packet, AVFrame *frame, void (Demuxer::* func)());


    void writeVideo();
    void writeAudio();
public:
    Demuxer();

    int demuxer(const char* videoPath, YUVFileSpec& yuvFileSpec, PCMFileSpec& pcmFileSpec);


};

#endif // DEMUXER_H
